/**
 * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

package fr.smile.liferay.portlet.news.model.impl;

import com.liferay.portal.kernel.util.LocalizationUtil;
import com.liferay.portal.kernel.util.StringPool;

import fr.smile.liferay.portlet.news.model.NewsEntry;
import fr.smile.liferay.portlet.news.util.LocaleTransformer;

/**
 * The model implementation for the NewsEntry service. Represents a row in the &quot;News_NewsEntry&quot; database
 * table, with each column mapped to a property of this class.
 * 
 * <p>
 * Helper methods and all application logic should be put in this class. Whenever methods are added, rerun
 * ServiceBuilder to copy their definitions into the {@link fr.smile.liferay.portlet.news.model.NewsEntry} interface.
 * </p>
 * 
 * <p>
 * Never reference this class directly. All methods that expect a news entry model instance should use the
 * {@link NewsEntry} interface instead.
 * </p>
 */
public class NewsEntryImpl extends NewsEntryModelImpl implements NewsEntry {
	public NewsEntryImpl() {
	}

	public String getDefaultLocale() {
		String xml = getContent();

		if (xml == null) {
			return StringPool.BLANK;
		}

		String defaultLanguageId = LocalizationUtil.getDefaultLocale(xml);

		return defaultLanguageId;
	}

	public String[] getAvailableLocales() {
		return LocalizationUtil.getAvailableLocales(getContent());
	}

	public String getContentByLocale(String languageId) {
		return getTextByLocale(getContent(), languageId);
	}

	public String getTitleByLocale(String languageId) {
		return getTextByLocale(getTitle(), languageId);
	}

	public String getDescriptionByLocale(String languageId) {
		return getTextByLocale(getDescription(), languageId);
	}

	public static String getTextByLocale(String content, String languageId) {
		LocaleTransformer transformer = new LocaleTransformer(languageId);
		return transformer.onXml(content);
	}
}
